import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'bottom_bar_widget_logic.dart';

// ignore: must_be_immutable
class BottomBarWidgetPage extends StatefulWidget {
  Function(Widget) onTap;

  BottomBarWidgetPage({this.onTap});

  @override
  _BottomBarWidgetPageState createState() => _BottomBarWidgetPageState();
}

class _BottomBarWidgetPageState extends State<BottomBarWidgetPage> {
  final BottomBarWidgetLogic logic = Get.put(BottomBarWidgetLogic());

  @override
  Widget build(BuildContext context) {
    return Obx(() {
      return BottomNavigationBar(
        selectedItemColor: Colors.red,
        currentIndex: logic.currentIndex.value,
        onTap: (v) {
          logic.setCurrentIndex(v);
          if (widget.onTap != null) widget.onTap(logic.listData[v].page);
        },
        items: List.generate(logic.listData.length, (index) {
          return BottomNavigationBarItem(
              icon: logic.listData[index].icon,
              label: logic.listData[index].label);
        }),
      );
    });
  }

  @override
  void dispose() {
    Get.delete<BottomBarWidgetLogic>();
    super.dispose();
  }
}
